﻿Public Class FormMain
    Dim objUser As New clsUser
    Dim objWorkshopCurrent As New clsWorkshopCurrent
    Dim objPgdMes As New clsPgdMes
    Dim objProdSpec As New clsProdSpec
    Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        connectDB()
        getUserListByCJ()
        initForm()
    End Sub

    Private Sub connectDB()
        g_szInitFileName = My.Application.Info.DirectoryPath & "\lxjc.ini"
        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If

    End Sub

    Private Sub getUserListByCJ()
        Dim dtUser As DataTable = objUser.getUserListByCJ(4)
        cmbOpers.Properties.Items.Clear()
        For index = 0 To dtUser.Rows.Count - 1
            cmbOpers.Properties.Items.Add(dtUser.Rows(index)("user_name"))
        Next
        If cmbOpers.Properties.Items.Count > 0 Then
            cmbOpers.Properties.Items(0).CheckState = CheckState.Checked
            cmbOpers.Properties.DropDownRows = cmbOpers.Properties.Items.Count + 1
        End If
        cmbOpers.Properties.ShowButtons = False
        cmbOpers.Properties.ShowPopupCloseButton = False
    End Sub

    Public Sub initForm()
        Dim dt As DataTable = objWorkshopCurrent.GetListByWorkShopIdAndCurrentSection("4")
        cmb_support_model.DisplayMember = "support_model"
        cmb_support_model.ValueMember = "b_pgd_sys_id"
        cmb_support_model.DataSource = dt
        If dt.Rows.Count > 0 Then
            If String.IsNullOrEmpty(cmb_support_model.Text) = False Then
                cmb_support_model.SelectedIndex = 0
                Dim dtPgdMes As DataTable = objPgdMes.getListBySysId(cmb_support_model.SelectedValue.ToString())
                txt_mes_project_code.Text = dtPgdMes.Rows(0)("mes_project_code").ToString()
                txt_mes_project_name.Text = dtPgdMes.Rows(0)("mes_project_name").ToString()
                lblProdSpecName.Text = objProdSpec.getSpecNameByID(cmb_support_model.Text)
            Else
                txt_mes_project_code.Text = String.Empty
                txt_mes_project_name.Text = String.Empty
                lblProdSpecName.Text = String.Empty
            End If
        End If
    End Sub

    Private Sub btnReceive_Click(sender As Object, e As EventArgs) Handles btnReceive.Click
        Dim formReceive = New FormReceive()
        formReceive.usr = cmbOpers.EditValue.ToString()
        formReceive.ShowDialog(Me)
    End Sub

    Private Sub btnKineticMeasurement_Click(sender As Object, e As EventArgs) Handles btnKineticMeasurement.Click
        Dim formKineticMeasurement = New FormKineticMeasurement()
        formKineticMeasurement.usr = cmbOpers.EditValue.ToString()
        formKineticMeasurement.ShowDialog(Me)
    End Sub

    Private Sub btnKineticMeasurementHistoryList_Click(sender As Object, e As EventArgs) Handles btnKineticMeasurementHistoryList.Click
        Dim formKineticMeasurementHistoryList = New FormKineticMeasurementHistoryList()
        formKineticMeasurementHistoryList.usr = cmbOpers.EditValue.ToString()
        formKineticMeasurementHistoryList.ShowDialog(Me)
    End Sub

    Private Sub btnLimitDetectionHistoryList_Click(sender As Object, e As EventArgs) Handles btnLimitDetectionHistoryList.Click
        Dim formLimitDetectionHistoryList = New FormLimitDetectionHistoryList()
        formLimitDetectionHistoryList.ShowDialog(Me)
    End Sub

    Private Sub btnLimitDetection_Click(sender As Object, e As EventArgs) Handles btnLimitDetection.Click
        Dim formLimitDetection = New FormLimitDetection()
        formLimitDetection.ShowDialog(Me)
    End Sub

    Private Sub btnHorizontalOffsetHistoryList_Click(sender As Object, e As EventArgs) Handles btnHorizontalOffsetHistoryList.Click
        Dim formHorizontalOffsetHistoryList = New FormHorizontalOffsetHistoryList()
        formHorizontalOffsetHistoryList.ShowDialog(Me)
    End Sub

    Private Sub btnHorizontalOffset_Click(sender As Object, e As EventArgs) Handles btnHorizontalOffset.Click
        Dim formHorizontalOffset = New FormHorizontalOffset()
        formHorizontalOffset.ShowDialog(Me)
    End Sub

    Private Sub btnRk_Click(sender As Object, e As EventArgs) Handles btnRk.Click
        If IsNothing(cmb_support_model.SelectedValue) = False Then
            Dim formRk As New FormRk()
            formRk.usr = cmbOpers.EditValue.ToString()
            formRk.PgdMesSysId = cmb_support_model.SelectedValue.ToString()
            formRk.ShowDialog(Me)
        Else
            MsgBox("请设定生产计划", vbYes, "提示")
        End If
    End Sub

    Private Sub btnLXCK_Click(sender As Object, e As EventArgs) Handles btnLXCK.Click
        Dim formLXCK As New FormLxCk()
        formLXCK.usr = cmbOpers.EditValue.ToString()
        formLXCK.ShowDialog(Me)
    End Sub

    Private Sub btnDeliver_Click(sender As Object, e As EventArgs) Handles btnDeliver.Click
        Dim formDeliver As New FormDeliver()
        formDeliver.usr = cmbOpers.EditValue.ToString()
        formDeliver.ShowDialog(Me)
    End Sub

    Private Sub btnMesPlan_Click(sender As Object, e As EventArgs) Handles btnMesPlan.Click
        Dim formPlanMes As New FormPlanMes()
        formPlanMes.usr = cmbOpers.EditValue.ToString()
        formPlanMes.ShowDialog(Me)
    End Sub

    Private Sub btnMesWorkReportList_Click(sender As Object, e As EventArgs) Handles btnMesWorkReportList.Click
        Dim formMesWorkReportList As New FormMesWorkReportList()
        formMesWorkReportList.ShowDialog(Me)
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        Dim rtn As Integer = objWorkshopCurrent.updateDataClear("0")
        If rtn = -2 Then
            MsgBox(btnClear.Text + "失败", vbYes, "提示")
        Else
            MsgBox(btnClear.Text + "成功", vbYes, "提示")
            initForm()
        End If
    End Sub

    Private Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
        If String.IsNullOrEmpty(cmbOpers.EditValue.ToString()) = False Then
            Dim formPlanMes As New FormPlanMes()
            formPlanMes.usr = cmbOpers.EditValue.ToString()
            formPlanMes.ShowDialog(Me)
        Else
            MsgBox("请选择用户！", vbYes, "提示")
        End If
    End Sub

    Private Sub FormMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        DBacs.Disconnect()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim formKineticMeasurement1 = New FormKineticMeasurement1()
        formKineticMeasurement1.usr = cmbOpers.EditValue.ToString()
        formKineticMeasurement1.ShowDialog(Me)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim formKineticMeasurement2 = New FormKineticMeasurement2()
        formKineticMeasurement2.usr = cmbOpers.EditValue.ToString()
        formKineticMeasurement2.ShowDialog(Me)
    End Sub
End Class




